﻿using System;
using System.Windows;

namespace WpfBindingIssue
{
    public partial class MainWindow : Window
    {
        private WeakReference _reference = default(WeakReference);
        public MainWindow() { InitializeComponent(); }

        private void btnShowWindow_Click(object sender, RoutedEventArgs e)
        {
            _reference = _reference ?? new WeakReference(new OtherWindowViewModel());
            new OtherWindow { DataContext = _reference.Target }.Show();
        }

        private void btnCheckIsAlive_Click(object sender, RoutedEventArgs e)
        {
            GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true);
            if (_reference == null)
                MessageBox.Show(false.ToString(), "Is it alive?");
            else
                MessageBox.Show(_reference.IsAlive.ToString(), "Is it alive?");
        }
    }

}
